using System;
using System.Windows.Forms;
using SG.Sys.Console.View;

namespace SG.Sys.Console.Tab
{
    static class TabPageHelper
    {
        public static TControl FillWith<TControl>(this TabPage @this, TControl control)
            where TControl : Control
        {
            if (@this == null)
                throw new ArgumentNullException("this");
            if (@this.Controls.Count > 0)
                throw new ArgumentException("The control is already filled!", "this");

            control.Dock = DockStyle.Fill;
            @this.Controls.Add(control);
            return control;
        }

        public static IConsolePane GetPane(this TabPage @this)
        {
            if (@this == null)
                throw new ArgumentNullException("this");
            if (@this.Controls.Count != 1)
                throw new ArgumentException("The control not filled!", "this");

            return @this.Controls.Count == 1 ? (ConsolePane)@this.Controls[0] : null;
        }
    }
}